package com.heima.controller;

import com.heima.pojo.GoodsClassName;
import com.heima.pojo.GoodsClassQueryParam;
import com.heima.pojo.PageBean;
import com.heima.service.GoodsClassService;
import com.heima.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/vm-service/skuClass")
public class GoodsClassController {
    @Autowired
    private UserService userService;
    @Autowired
    private GoodsClassService goodsClassService;

    @PostMapping("")
    @ApiOperation("添加商品类别")
    public boolean addGoodsClass(@RequestBody GoodsClassName goodsClassName) {
        log.info("要添加的商品类别为：{}", goodsClassName);
        return userService.addGoodsClass(goodsClassName);
    }

    /**
     * 商品类型分页查询
     *
     * @param goodsClassQueryParam
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("商品分类搜索")
    public PageBean queryGoodsClass(GoodsClassQueryParam goodsClassQueryParam) {
        log.info("要查询的起始数，商品总页数,可选className 为：{}", goodsClassQueryParam);
        PageBean pageBean = goodsClassService.GoodsClasslist(goodsClassQueryParam);
        return pageBean;
    }

    /**
     * 根据classId查询
     *
     * @param classId
     * @return
     */
    @ApiOperation("根据id查询信息")
    @GetMapping("/{classId}")
    public GoodsClassName selectGoodsClassNameById(@PathVariable String classId) {
        log.info("要查询的商品类型ID为：{}", classId);
        GoodsClassName result = goodsClassService.selectByID(classId);
        return result;
    }

    /**
     * 修改
     * @param classId
     * @param GoodsClass
     * @return
     */
    @ApiOperation("修改className")
    @PutMapping("/{classId}")
    public boolean upDateClassName(@PathVariable String classId,@RequestBody GoodsClassName GoodsClass){
        log.info("要修改的className为：{},{}",classId,GoodsClass.getClassName());
        return goodsClassService.upDateClassName(classId,GoodsClass.getClassName());
    }
    @DeleteMapping("/{classId}")
    @ApiOperation("删除")
    public void deleteClassName(@PathVariable String classId){
        log.info("要删除的classID为:{}", classId);
        goodsClassService.deleteClassName(classId);
    }



}
